
var reviewFlag =  $("#reviewFlag").val();//是否已经发表评论
var invitationFlag = $("#invitationFlag").val();//是否可以邀请
var joinFlag = $("#joinFlag").val();//是否可以报名 false:未报名，true已报名
var collectFlag =  $("#collectFlag").val();//是否已经收藏 
var activityId = $("#activityId").val();
var actDate="";
var timer="";
var fdetailsId;//选择的活动收费信息
var activity="";
var reviews = "";//评论提示语句
var activityPhaseId = "";
var currentDate;

/**
 * 活动详情
 */
$(function(){

	$('.colsed').click(function(){
		$('#chargeModal').slideUp();
		window.location.reload();
	})


	//团圆弹框关闭
	mui("body").on("tap",".closeTyModal1",function(){
		$(".ty-msgmodal").hide();
		$(".mui-popup-backdrop").hide();
	});
	mui("body").on("tap",".closeTyModal2",function(){
		$(".ty-msgmodal").hide();
		$(".mui-popup-backdrop").hide();
	});
	mui("body").on("tap","#goToAuthentication",function(){
		$(".ty-msgmodal1").hide();
		$(".ty-msgmodal2").show();
	});
	mui("body").on("tap","#goToAuthentication2",function(){
		var empName =$(".empName").val();
    	var idCard =$(".idCard").val();
    	if(empName==""||empName==null||empName==undefined){
    		 mui.alert("请输入真实姓名");
    		return;
    	}
    	if(idCard==""||idCard==null||idCard==undefined){
    		 mui.alert("请输入身份证号码");
    		return;
    	}
     if(idCard.length!==18){
    	 mui.alert("请输入正确的身份证号码");
    		return;
    	}
    	$.ajax({
        	type:'post',
            url:config.server+'cyl/webChartApplyAudit',
            data:{
            	empName:empName,
				idCard:idCard
            },
            success:function(result){
                var result=JSON.parse(result);
            	if(result.status==0){
            		$(".ty-msgmodal2").hide();
            		$(".ty-msgmodal3").show();
            	}else if(result.status==1){
    				$(".ty-msgmodal2").hide();
    				$(".mui-popup-backdrop").hide();
    				 mui.alert("网络错误，请稍后再试！");
    			}else if(result.status==2){
    				$(".ty-msgmodal2").hide();
    				$(".mui-popup-backdrop").hide();
    				 mui.alert("该团员认证信息已被其他青春上海Act+用户绑定，请输入其他团员认证信息！");
    			}else if(result.status==3){
    				$("#cylFlag").val("1");
    				/*if(result.data.individualOpenId!=null){
                        $("#openid").val(result.data.individualOpenId);
					}else if (result.data.qqOpenid!=null){
                        $("#qqOpenid").val(result.data.qqOpenid);
					}else if (result.data.xinlang!=null){
                        $("#xinlang").val(result.data.xinlang);
                    }*/
    				$(".ty-msgmodal2").hide();
    				$(".mui-popup-backdrop").hide();
    				 mui.alert("恭喜您，您的团员身份已被认证，继续报名吧！");
    			}
            }
    	});
	});
	mui("body").on("tap","#goToAuthentication3",function(){
		$(".ty-msgmodal").hide();
		$(".mui-popup-backdrop").hide();
		window.open("http://tuanyuanzheng.shyouth.net/SPESTY/RT/TYRT14.jsp");
	});
	//分享
	var shareUrl=window.location.href;
	var titles ="【活动】" +$(".title h3").html();
	var coverPicture =$("#coverPicture").val();
//	var describe = $("#describes").val();
	var activityDetails = $("#activityDetails").val();
	var otherDescribes="【活动】" +$(".title h3").html();
	var describes = "【青春上海Act+ 活动】" +$(".title h3").html();
	_comm.wxShare(shareUrl,titles,coverPicture,describes,otherDescribes);
	
	if($("#collectionForm > div.input-item").length == 1)
		$("#bxModal .mui-scroll-wrapper").css("height","190px");
	if($("#collectionForm > div.input-item").length == 2)
		$("#bxModal .mui-scroll-wrapper").css("height","260px");
	if($("#collectionForm > div.input-item").length > 2)
		$("#bxModal .mui-scroll-wrapper").css("min-height","300px");
	
	//关闭弹窗
	mui('.act-popover').on('tap', '.colse_msg', function() {
		mui('.act-popover').popover('hide');
		window.location.reload();
	});
	//关闭弹窗
	mui('.act-popover').on('tap', '.colsed', function() {
		mui('.act-popover').popover('hide');
	});
	//过滤固话 固话不能直接拨打
	var tel = $("#contacWay").attr("data-tel");
	if(tel.length == 11&&tel.indexOf("-") == -1||tel.length == 7||tel.length == 8||tel.length == 10){
		$("#contacWay").attr("href","tel:"+tel);
		$("#contacWay span.r-icons").show();
	}
	else {
		$("#contacWay").attr("href","javascript:;");
		$("#contacWay span.r-icons").hide();
	}
	//查询数据
	searchActivityDetail();
	//表单验证

	$("#in-4").on("focus",function(){
		$(this).attr("type","date");
	});
	$("#in-5").on("focus",function(){
		$(this).attr("type","email");
	});
	 var dataOptions={type:"date",beginYear:"1930",endYear:"2030",value:""};
		  mui(".wealApply").on("tap",".apply-phone",function(){
		var _this=this;
		var picker = new mui.DtPicker(dataOptions);
		picker.show(function(rs) {
			_this.value = rs.value;
			picker.dispose();
		});
		  });
	if ($("#userTypeId").val()==1){
        var genderPicker = new mui.PopPicker();
        genderPicker.setData([{
            value: '1',
            text: '男'
        }, {
            value: '2',
            text: '女'
        }]);
        mui(".wealApply").on("tap",".sex-picker",function(){
            var _this = this;
            genderPicker.show(function(items) {
                _this.value = items[0].text;
            });
        });
	}

//	var isCheck = false;
	mui("#bxModal").on("tap","#okSubmit",function(){
//		var length  =$("#collectionForm .inputN").size();
		if($("#model1").val()==""){
			mui.alert("手机号不能为空!");
			return;
		}
		if(!validateMobile($("#model1").val())){
			mui.alert("请输入有效的手机号!");
			return;
		}
		console.log($("#model2").val())
		if($("#model2").val()==""){
			mui.alert("姓名不能为空!");
			return;
		}
		if($("#model3").val()==""){
			mui.alert("性别不能为空!");
			return;
		}
		if($("#model4").val()==""){
			mui.alert("出生年月不能为空!");
			return;
		}
		if($("#model5").val()==""){
			mui.alert("电子邮箱不能为空!");
			return;
		}
		if($("#model5").val()!=null&&$("#model5").val()!=undefined&&$("#model5").val()!=""){
			var reg =/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
			if(!(reg.test($("#model5").val()))){
				mui.alert("请输入正确的电子邮箱！");
				return;
			}
		}
		

		if($("#model6").val()==""){
			mui.alert("通讯地址不能为空!");
			return;
		}
		if($("#model7").val()==""){
			mui.alert("工作单位或学校不能为空!");
			return;
		}
		if($("#model8").val()==""){
			mui.alert("身份证号码不能为空!");
			return;
		}
		if($("#model8").val()!=null&&$("#model8").val()!=undefined&&$("#model8").val()!=""){
			if(!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test($("#model8").val()))){
				mui.alert("请输入正确的身份证号码！");
				return;
			}
		}
		var length= $(".singleLineTextContent").size()
		for(var i=0;i<length;i++){
			if($(".singleLineTextContent").eq(i).val()==""){
				var placeholderTxt = $(".singleLineTextContent").eq(i).attr("placeholder");
				mui.alert(placeholderTxt+"不能为空!");
				return;
			}
		}
		var length= $(".multiLineTextContent").size()
		for(var i=0;i<length;i++){
			if($(".multiLineTextContent").eq(i).val()==""){
				var placeholderTxt = $(".multiLineTextContent").eq(i).attr("placeholder");
				mui.alert(placeholderTxt+"不能为空!");
				return;
			}
		}

//		$("#collectionForm .inputN").each(function(i,v){
//			var labelHtml=$(v).attr("placeholder");
//			var val=$.trim($(v).val());
//			if(labelHtml=="出生年月日"){
//				if(val.length==0){
//					mui.alert("出生年月不能为空");
//					isCheck = false;
//					return true;
//				}else{
//					isCheck = true;
//				}
//			}else if(labelHtml=="电子邮箱"){
//				var reg =/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
//				if(val.length==0){
//					mui.alert("电子邮箱不能为空");
//					isCheck = false;
//					return true;
//				}else {
//					if(!reg.test(val)){
//						mui.alert("请输入合法的电子邮箱");
//						isCheck = false;
//						return true;
//					}else{
//						isCheck = true;
//					}
//				}
//			}else if(labelHtml=="性别"){
//				if(val.length==0){
//					$(v).next().css("display","block").text("性别不能为空");
//					isCheck = false;
//					return true;
//				}else {
//					if(val!="男" && val!="女"){
//						$(v).next().css("display","block").text("请输入正确的性别（男、女）");
//						isCheck = false;
//						return true;
//					}else{
//						isCheck = true;
//					}
//				}
//			}else if(labelHtml=="联系手机"){
//				var reg=/^1[3|4|5|7|8]\d{9}$/;
//				if(val.length==0){
//					mui.alert("手机不能为空");
//					isCheck = false;
//					return true;
//				}else{
//					if(!reg.test(val)){
//						 mui.alert("请输入正确的手机号码");
//						isCheck = false;
//						return true;
//					}else{
//						isCheck = true;
//					}
//				}
//			}else if(labelHtml=="身份证号码"){
//				var reg=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
//				if(val.length==0){
//					 mui.alert("身份证不能为空");
//					isCheck = false;
//					return true;
//				}else{
//					if(!reg.test(val)){
//						 mui.alert("请输入正确的身份证号码");
//						isCheck = false;
//						return true;
//					}else{
//						isCheck = true;
//					}
//				}
//			}
//		});
		//表单验证完成
//		if(isCheck){
			var data = $("#collectionForm").serializeArray(); //自动将form表单封装成json
			console.log(data);
			var collectionArray = [];//定义一个数组
			
			var number =0;
			var collection;
			for(var i = 0 ; i < data.length; i ++ ){
				if(i%3==0){
					collection = {
							content: "",
							collecttionInfoId:"",
							collectType:""
					};
				}
				
				var one = data[i];
				if(i%3==0){
					collection.collecttionContent = one.value;
				}
				if(i%3==1){
					collection.collecttionInfoId = one.value;
				}
				if(i%3==2){
					collection.collectType = one.value;
					collectionArray[number] = collection;
					
					number++;
				}
			}
			
			// 当前账号没有手机号码 并且填写的手机号码已报名 提示去绑定手机 20170511 ST
			var userLoginName=$("#userMobile").val();
			// 20170511 ED
			var  queryParamReg = {
					activityId: activityId,
					activityPhaseId: activityPhaseId,
					fdetailsId: fdetailsId,
			};
			var params={
					coll:collectionArray,
					reg :queryParamReg,
					tmpMobile : $("#model1").val(),
					tmpUser : $("#model2").val(),
					// 当前账号没有手机号码 并且填写的手机号码已报名 提示去绑定手机 20170511 ST
					userLoginName: userLoginName
					// 20170511 ED
			};
			$.ajax({  
				type: "post", // 请求方式  
				url: config.webCompletInfo, //url地址  
				data:JSON.stringify(params), //数据  
				contentType: "application/json",  
				dataType: "json",  
				success: function (result) {  
					// 当前账号没有手机号码 并且填写的手机号码已报名 提示去绑定手机 20170511 ST
//					var bindFlag = result.data.bindFlag;
//					if (null != bindFlag && bindFlag == 1) {
//						mui.confirm("当前账号没有手机号码,并且填写的手机号码已报名,请绑定手机号码!", function(e) {
//							if (e.index == 1) {
//								location.href = BASE_URL+"/webChat/userCenter/toBindAccount";
//							}
//						});
//						return;
//					}
					// 20170511 ED
					joinFlag = true;//是否可以报名 false:未报名，true已报名	
					mui('.act-popover').popover('hide');
					$("#bmButton").html("我已报名");
					$("#bmButton").removeClass("s-btn-blue");
					$("#bmButton").addClass("s-btn-gray");
					$("#bmButton").attr("href","");
					$(".bottom-flex").show();
					//mui.alert("完善信息成功,请关注 '我的消息' 中报名结果动态");
					mui.confirm("完善信息成功,<br/>请关注 '我的消息' 中报名结果动态!", function(e) {
						if (e.index == 1) {
							location.href = BASE_URL+"/webChat/userCenter/toMyMessage";
						}
					})
//					window.location.reload();
					
				}, error: function () {  
					mui.alert("error");  
				}  
			});
//		}
	});
	

	
	
});
/**
 * 画面数据查询数据
 */
function searchActivityDetail() {
	$.ajax({  
		url:config.searchActivityDetail,
		data:{  
			activityId:activityId
		},  
		type:'POST',
		cache:true,  
		dataType:'json',  
		success:function(result) {  
			activity = result.data.activity;
			currentDate = result.data.currentDate;
			actDate = result.data.actDate;
			
			//已经报名的情况下
			console.log(activity.uerActivityApplyStatus)
			if(activity.uerActivityApplyStatus == '2'){
				var detailId = result.data.detailId;
				if(!isNullOrEmpty(detailId)){
					fdetailsId = detailId;
				}
				//变按钮颜色和文字
				$("#bmButton").removeClass("s-btn-gray");
				$("#bmButton").addClass("s-btn-blue");
				$("#bmButton").html("去完善");
				$("#bmButton").attr("href","#bxModal");	
				$(".bottom-flex").show();
				showCompleteInfo();
			}else if(activity.uerActivityApplyStatus == 1){
				if(activity.activityFeeDetailsRemainMembers==0){
					$("#bmButton").html("名额已满");
					$("#bmButton").removeClass("s-btn-blue");
					$("#bmButton").addClass("s-btn-gray");
					$("#bmButton").attr("href","");
					$(".bottom-flex").show();
				}else{
					$("#bmButton").html("我要报名");
					$("#bmButton").removeClass("s-btn-gray");
					$("#bmButton").addClass("s-btn-blue");
					$("#bmButton").attr("href","#chargeModal");
					$(".bottom-flex").show();
				}
			} else if(activity.uerActivityApplyStatus == 3){
				$("#bmButton").html("我已报名");
				$("#bmButton").removeClass("s-btn-blue");
				$("#bmButton").addClass("s-btn-gray");
				$("#bmButton").attr("href","");
				$(".bottom-flex").show();
			}
			
			//用户是否收藏
			var collectFlag = activity.collectFlag;
			if(collectFlag){
				//已收藏
				$("#collectNumber").html("<i class='star-yes'></i>"+activity.collectCount);
			}else{
				//未收藏
				$("#collectNumber").html("<i class='star-no'></i>"+activity.collectCount);
			}
			
			// 运营维护 20170526 点赞功能 ST
			var zanFlag = activity.zanFlag;
			if(zanFlag==true||zanFlag=="true"){
				//已赞
				$("#zanNumber").html("<i class='zan-yes'></i>"+activity.zanCount);
			}else{
				//未赞
				$("#zanNumber").html("<i class='zan-no'></i>"+activity.zanCount);
			}
			
			// 运营维护 20170526 点赞功能 ED
			
            var activityPhaseFeeDetailsList = activity.activityPhases[0].activityPhaseFeeDetailses;
            var payFlagDiv = false;//falase :不显示支付说明，true :显示支付说明
            for(var i = 0 ; i < activityPhaseFeeDetailsList.length;i++ ){
            	
            	var fdetailsFeeType = activityPhaseFeeDetailsList[i].fdetailsFeeType;
            	
            	if(fdetailsFeeType == 1){
            		payFlagDiv =true;
            		break;
            	}
            }
            
            if(payFlagDiv){
            	$("#payFlagDiv").show();
            }else{
            	$("#payFlagDiv").hide();
            }
			
		
			//活动时间
			activityPhaseId = activity.activityPhases[0].activityPhaseId;
			
            //报名开始时间
            var startDate = activity.activityPhases[0].activityPhaseStart;
            //报名结束时间
            var endDate = activity.activityPhases[0].activityPhaseEnd;
            
            //当前时间
            var nowDate = parseInt(currentDate);
            
            var buckets = activity.activityPhases[0].activityPhaseTimeBuckets;
            //最大的活动结束时间
            var maxActivityEndDate=0;
            //最小的活动开始时间
            var minActivityStartDate=0;
            for(var i=0;i<buckets.length;i++){
            	var star = buckets[i].activityDateStart;
            	if(i==0){
            		minActivityStartDate = star;
            	}else{
            		if(star<minActivityStartDate){
            			minActivityStartDate = star;
            		}
            	}
            	var end = buckets[i].activityDateEnd;
            	if(end>maxActivityEndDate){
            		maxActivityEndDate = end;
            	}
            }
            
            var date;
            var countdown;

            //根据时间判断活动现在处于哪个阶段
            if(nowDate<startDate){//预热阶段
            	countdown='报名开始';
            	date= dateFormat(startDate);
            	//$("#bmButton").hide();//我要报名按钮删除
            	$("#bmButton").attr("disabled","disabled");
            	$("#bmButton").removeClass("s-btn-blue");
				$("#bmButton").addClass("s-btn-gray");
				$("#bmButton").attr("href","");	
            	$("#bmButton").html("即将开始报名");//我要报名按钮删除
            	$(".bottom-flex").show();
            }else if(startDate<nowDate && nowDate<endDate){//报名中           	
            	countdown='报名中';
            	date= dateFormat(endDate);
            }else if(endDate<nowDate && nowDate <minActivityStartDate){
            	//当前时间在 报名结束时节和活动开始时间之间 
            	countdown='活动开始';
            	date= dateFormat(minActivityStartDate);
            	$("#bmButton").attr("disabled","disabled");
            	$("#bmButton").removeClass("s-btn-blue");
				$("#bmButton").addClass("s-btn-gray");
				$("#bmButton").attr("href","");
            	$("#bmButton").html("报名结束");//我要报名按钮删除
            	$(".bottom-flex").show();
            }else if(nowDate>minActivityStartDate && nowDate<maxActivityEndDate){	
            	//当前时间 大于最小活动开始时间
            	countdown='活动结束';
            	date= dateFormat(maxActivityEndDate);
            	$("#bmButton").removeClass("s-btn-blue");
				$("#bmButton").addClass("s-btn-gray");
            	$("#bmButton").attr("disabled","disabled");
            	$("#bmButton").attr("href","");
            	$("#bmButton").html("活动中");//我要报名按钮删除
            	$(".bottom-flex").show();
            }else if(nowDate>=maxActivityEndDate){
            	//当前时间大于 最大活动时间
            	countdown='活动已结束';
            	date='';
            	$("#bmButton").removeClass("s-btn-blue");
				$("#bmButton").addClass("s-btn-gray");
            	$("#bmButton").attr("disabled","disabled");
            	$("#bmButton").html("活动结束");//我要报名按钮删除
            	$("#bmButton").attr("href","");
            	$(".bottom-flex").show();
            }
            
            //设置倒计时
           _Act.activity.countDown(date,"#countDown");
            //文字设置
            $("#countDownHear").html(countdown);
            
            //完善信息标题
            //报名形式(0-秒杀 1-踩楼 2-随机 3-审核)
           /* var showHeaderStr =""
            if(activity. activityApplyType == 0){
            	showHeaderStr = "秒杀";
            }
            if(activity. activityApplyType == 1){
            	showHeaderStr = "踩楼";
            }
            if(activity. activityApplyType == 3){
            	showHeaderStr = "申请参加";
            }
             
            $("#headHtmlStr").html("请您在15分钟内完善报名信息，否则视为自动放弃参与资格哦！");*/
            
            //默认
            fdetailsId = activity.activityPhases[0].activityPhaseFeeDetailses[0].fdetailsId;
		} 
	});
}

/**
 * 完善资料展示
 */
 function showCompleteInfo(){
	var interval="";
	var minute="";
	var second="";
	var timeDiff="";
 	if(actDate==null||actDate==""){
 		timeDiff=0;
 		minute= 15;
 		second= 0;
    	//showResult("completeInfo",$scope);
	}else{
		var date = new Date(currentDate);
		//报名时间与当前时间的  时间差 (秒)
		timeDiff = Math.round((parseInt(date.getTime())-parseInt(actDate))/1000);
		if(timeDiff>900){
			return;//超过15分钟  则报名取消   不显示倒计时
		}else{
			//showResult("completeInfo",$scope);
		}    		
	}   	   	   	
	    interval=setInterval(function(){
			//整除
			if(timeDiff%60==0){
				minute = (900-timeDiff)/60;
				second = 0 ;
			}else{
				minute = parseInt((900-timeDiff)/60);
				second = (900-timeDiff)-minute*60;
			}
			timeDiff = timeDiff+1;
			if(minute>=10){
				var minuteOne=minute.toString().substring(0,1);
				var minuteTwo=minute.toString().substring(1,2);
				$("#minuteOne").html(minuteOne);
				$("#minuteTwo").html(minuteTwo);
			}else{
				$("#minuteOne").html("0");
				$("#minuteTwo").html(minute);
			}
			if(second>=10){
				var secondOne=second.toString().substring(0,1);
				var secondTwo=second.toString().substring(1,2);
				$("#secondOne").html(secondOne);
				$("#secondTwo").html(secondTwo);
			}else{
				$("#secondOne").html("0");
				$("#secondTwo").html(second);
			}
			if(timeDiff>900){
				//completeInfoTimeOut();//调用取消报名方法
				clearInterval(interval);
				window.location.reload();
			}
	    },1000);
}

//时间戳转日期
function dateFormat(time) {
	if(null!=time){
		var date = new Date(time);
		var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h=date.getHours();
        h = date.getHours()<10?('0'+h):h;
        var minute = date.getMinutes();
        minute = minute < 10 ? ('0' + minute) : minute;
        var second = date.getSeconds();
        second = second < 10 ? ('0' + second) : second;
        return y + '/' + m + '/' + d+' '+h+':'+minute +':'+second;
	}else{
		return "";
	}
    
};


/**
 * 格式化时间
 */
function formatterDateTime(time) {
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    //return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
    
    return year + "-" + month + "-" + date;
}

/**
 * 点击收藏
 */
function activityCollect() {
	var userType=$("#userType").val();
	var userLoginName=$("#userMobile").val();
    var openid=$("#openid").val();
	var qqOpenid=$("#qqOpenid").val();
	var xinlang=$("#xinlang").val();
	var twUserId=$("#twUserId").val();
	if(userType==1 || userType=="1"){
		if((""==userLoginName || null==userLoginName || userLoginName==undefined)
				&& (""==openid || null==openid || openid==undefined)
				&& (""==qqOpenid || null==qqOpenid || qqOpenid==undefined)
				&& (""==xinlang || null==xinlang || xinlang==undefined)
				&& (undefined!=twUserId && null!=twUserId && ""!=twUserId)){
			window.location.href = config.server+ "cyl/toWechatBand?TWUserId="+twUserId+"&type=02activityId_"+$("#activityId").val();
			//window.location.href = config.server+ "cyl/toWechatBand?TWUserId="+twUserId+"&type=02";
			return;
		} 
	}
	//已经收藏后不可以再次收藏
	if(collectFlag == true || collectFlag == "true"){
		
		mui.alert("您已经收藏了本活动");
		return false;
	}
	
	$.ajax( {  
		url:config.activityCollect,
		data:{  
			activityId		:	$("#activityId").val(),
			collectionType	:	"001"
		},  
		type:'POST',
		cache:true,  
		dataType:'json',  
		success:function(result) {  
			
			if(result.data.succFlag == "0"){
				$("#collectNumber").empty();
				var newcollectNumber = result.data.collectionCount;
				var loadHtml='<i class="icons-all icon-star"></i>'+newcollectNumber;
				$("#collectNumber").append(loadHtml);//填充HTML代码
				
				mui.alert(result.data.msg);
			}else{
				//mui.alert(result.data.msg);
				sessionStorage.removeItem("logins");
				// 取消报名绑定标记
				sessionStorage.removeItem("binds");
				$("#signModel").show();
		  		$(".mui-popup-backdrop").show();
			}

		} 
	});
}

// 运营维护 20170526 点赞功能 ST
/**
 * 点击赞
 */
mui("#zanNumber").on("tap","i",function(){
	var userType=$("#userType").val();
	var userLoginName=$("#userMobile").val();
    var openid=$("#openid").val();
	var qqOpenid=$("#qqOpenid").val();
	var xinlang=$("#xinlang").val();
	var twUserId=$("#twUserId").val();
	if(userType==1 || userType=="1"){
		if((""==userLoginName || null==userLoginName || userLoginName==undefined)
				&& (""==openid || null==openid || openid==undefined)
				&& (""==qqOpenid || null==qqOpenid || qqOpenid==undefined)
				&& (""==xinlang || null==xinlang || xinlang==undefined)
				&& (undefined!=twUserId && null!=twUserId && ""!=twUserId)){
			window.location.href = config.server+ "cyl/toWechatBand?TWUserId="+twUserId+"&type=02activityId_"+$("#activityId").val();
			return;
		} 
		
		// 点赞功能 不必要一定绑定手机
//		// 第三方登录 没有绑定手机的情况 跳转到手机绑定页面
//		if ((""==userLoginName || null==userLoginName || userLoginName==undefined)
//				&& ((openid !=undefined && null !=openid && "" !=openid) 
//						|| (qqOpenid !=undefined && null !=qqOpenid && "" !=qqOpenid)
//						|| (xinlang !=undefined && null !=xinlang && "" !=xinlang))) {
//			// 20170524 第三方活动点赞 账号绑定
//			if (activityId.indexOf("act_")>=0) {
//				window.location.href = config.webChat+ "userCenter/toBindAccount?state=" + activityId;
//			} else {
//				window.location.href = config.webChat+ "userCenter/toBindAccount?state=" + "act_" + activityId;
//			}
//			return;
//		}
	}
	
	var newcollectNumber = parseInt(this.nextSibling.data);
	
	// 点赞后再点取消点赞
	if(zanFlag.value == true || zanFlag.value == "true"){
		$.ajax({  
			url:config.cancelActivityZanCollect,
			data:{  
				referenceId	:	activityId,
				zanType	:	"001"
			},  
			type:'POST',
			cache:true,  
			dataType:'json',  
			success:function(result) {  
				
				if(result.status == "0"){

					$("#zanNumber").empty();
					var loadHtml='<i class="zan-no"></i>'+(newcollectNumber - 1);
					$("#zanNumber").append(loadHtml);//填充HTML代码
					
					zanFlag.value = false;
				}else{
					if (result.status != "2"){
						sessionStorage.removeItem("logins");
						// 取消报名绑定标记
						sessionStorage.removeItem("binds");
						$("#signModel").show();
				  		$(".mui-popup-backdrop").show();
					}
				}
			} 
		});

	}else{
		// 点赞
		$.ajax( {  
			url:config.addActivityZanCollect,
			data:{  
				referenceId	:	activityId,
				zanType	:	"001"
			},  
			type:'POST',
			cache:true,  
			dataType:'json',  
			success:function(result) {  
				
				if(result.status == "0"){
					$("#zanNumber").empty();
					var loadHtml='<i class="zan-yes"></i>'+(newcollectNumber + 1);
					$("#zanNumber").append(loadHtml);//填充HTML代码
					
					zanFlag.value = true;
				}else{
					if (result.status != "2"){
						sessionStorage.removeItem("logins");
						// 取消报名绑定标记
						sessionStorage.removeItem("binds");
						$("#signModel").show();
				  		$(".mui-popup-backdrop").show();
					}
				}

			} 
		});
	}
})
//运营维护 20170526 点赞功能 ED

/**
 * 选择的收费信息
 * @param fdetailsId
 */
function selectOne(obj){
	fdetailsId = obj.id;//选择的活动收费标准ID
}

/**
 * 提交报名信息
 * @param fdetailsId
 */
var isDisabled = false;//控制按钮点击次数
function joinActivity(){
	// var userType = $("#userType").val();
	// if(null==userType || userType==undefined || userType==""){
	// 	//mui('#chargeModal').popover('hide');//隐藏收费标准
	// 	sessionStorage.removeItem("logins")
	// 	// 活动报名 绑定标记删除(未绑定时 需要进行绑定)
	// 	sessionStorage.setItem("binds","toBind");
	// 	$("#signModel").show();
	// 	$(".mui-popup-backdrop").show();
	// 	return;
	// }
	var userLoginName=$("#userMobile").val();
    var openid=$("#openid").val();
	var qqOpenid=$("#qqOpenid").val();
	var xinlang=$("#xinlang").val();
	var twUserId=$("#twUserId").val();
	// if(userType==1 || userType=="1"){
	// 	if((""==userLoginName || null==userLoginName || userLoginName==undefined)
	// 			&& (""==openid || null==openid || openid==undefined)
	// 			&& (""==qqOpenid || null==qqOpenid || qqOpenid==undefined)
	// 			&& (""==xinlang || null==xinlang || xinlang==undefined)
	// 			&& (undefined!=twUserId && null!=twUserId && ""!=twUserId)){
	// 		window.location.href = config.server+ "cyl/toWechatBand?TWUserId="+twUserId+"&type=02activityId_"+$("#activityId").val();
	// 		//window.location.href = config.server+ "cyl/toWechatBand?TWUserId="+twUserId+"&type=02";
	// 		return;
	// 	} 
		
	// 	// 第三方登录 没有绑定手机的情况 跳转到手机绑定页面
	// 	if ((""==userLoginName || null==userLoginName || userLoginName==undefined)
	// 			&& ((openid !=undefined && null !=openid && "" !=openid) 
	// 					|| (qqOpenid !=undefined && null !=qqOpenid && "" !=qqOpenid)
	// 					|| (xinlang !=undefined && null !=xinlang && "" !=xinlang))) {
	// 		// 20170524 第三方活动报名 账号绑定
	// 		if (activityId.indexOf("act_")>=0) {
	// 			window.location.href = config.webChat+ "userCenter/toBindAccountSign?state=" + activityId;
	// 		} else {
	// 			window.location.href = config.webChat+ "userCenter/toBindAccountSign?state=" + "act_" + activityId;
	// 		}
	// 		return;
	// 	}
		
	// }
	var checked =$("#agreement").prop("checked");
	if(!checked){
		mui.alert("请阅读报名须知！");
		return;
	}
	// if($("#activityApplyScopeFlag").val() == 2 && $("#cylFlag").val()!=1){
	// 	//mui.alert("该活动为团员专属活动!");
	// 	$(".ty-msgmodal1").show();
	// 	$(".mui-popup-backdrop").show();
	// 	return;
	// }
	var flag = isNullOrEmpty(fdetailsId);

	// if(flag){
	// 	mui.alert("请选择对应的活动收费！");
	// }else{


	/*报名信息获取*/
	 var validator = new Validator('sign');
      var user_name  = document.forms['sign'].elements['name'].value;
      // alert("5555");
      // validator.required('activity_name', activity_name_not_null);
      // if (document.forms['sign'].elements['cat_id'].value == 0)
      // {
      //     validator.addErrorMsg(goods_cat_not_null);
      // }

      // checkVolumeData("1",validator);
      // if (document.forms['sign'].elements['activity_phone'].value == '')
      // {
      //     validator.required('activity_phone', activity_phone_not_null);
      // }else{
      //     validator.isNumber('activity_phone', activity_phone_not_number, true);
      // }
      
      /*判断活动结束时间是否大于开始时间*/
      var phone=document.forms['sign'].elements['phone'].value;
      var sex=document.forms['sign'].elements['sex'].value;
      var work=document.forms['sign'].elements['work'].value;


			if(!isDisabled){
			isDisabled = true;
			$("#next").html("报名中...");
			$.ajax({  
				url:config.joinActivity,
				data:{  
					user_name		:	user_name,
					phone	:	phone,
					sex	:	sex,
					work	:	work
				},  
				type:'POST',
				cache:true,  
				dataType:'json',  
				success:function(result) { 
					$("#next").html("下一步");
					mui('#chargeModal').popover('hide');//隐藏收费标准
					isDisabled = false;
					currentDate = result.data.currentDate;//当前时间
					// if(result.status==4){
					// 	//定向申请活动，用户没有申请权限
					// 	joinFlag = false;
					// 	//提示失败
					// 	mui.alert("您不是定向人员，无法报名");
					// }else if(result.status==3){
					// 	//已报名，并且完善了信息
					// 	mui('#bxModal').popover('hidden');//隐藏完善信息框
					// 	mui('#successModal').popover('hidden');//隐藏失败提示框
					// 	joinFlag = true;
					// 	mui.alert("您已经报名");
					// }else if(result.status==2){
					// 	actDate = result.data.actDate;//活动开始时间
					// 	showCompleteInfo();
					// 	//已报名  请完善资料（报名成功弹出完善信息画面）
					// 	mui('#bxModal').popover('show');//显示完善信息框
					// 	mui('#successModal').popover('hidden');//隐藏失败提示框
					// }else 
					if(result.status==1){
						showCompleteInfo();
						joinFlag =true;
						//报名成功（报名成功弹出完善信息画面）
						mui('#bxModal').popover('show');//显示完善信息框
						mui('#successModal').popover('hidden');//隐藏失败提示框
						//变按钮颜色和文字
						//$("#bmButton").html("我已报名");
						$("#bmButton").removeClass("s-btn-blue");
						$("#bmButton").addClass("s-btn-gray");
						$("#bmButton").attr("href","");
					}
					// else if(result.status==0){
					// 	//报名失败(审核是不存在报名失败的，后台可以审批不通过，但是前台显示的都是报名成功)
					// 	mui('#bxModal').popover('hidden');//隐藏完善信息框
					// 	$("#activityApplyMembers").html(result.data.newStepNumber + "位")
					// 	mui('#successModal').popover('show');//显示失败提示框
					// }else if(result.status==5){//完善信息，但没有通过审核
					// 	//没有通过审核
					// 	mui('#checkShow').popover('show');//显示完善信息框
					// 	mui('#successModal').popover('hidden');//隐藏失败提示框
					// }else if(result.status.status==6){
					// 	mui.alert(result.data.msg);
					// }
				} 
			});
		}
	// }
}

/**
 * 检查字符串
 * @param strVal
 * @returns {Boolean}
 */
function isNullOrEmpty(strVal) {
	if (strVal == '' || strVal == null || strVal == undefined) {
		return true;
	}else{
		return false;
	}
}

/**
 * 提交完善信息
 */
/*function completeInformation(){	
	var data = $("#collectionForm").serializeArray(); //自动将form表单封装成json
	var collectionArray = [];//定义一个数组
	
	var number =0;
	var collection;
	for(var i = 0 ; i < data.length; i ++ ){
		if(i%3==0){
			collection = {
					content: "",
					collecttionInfoId:"",
					collectType:""
			};
		}

		var one = data[i];
		if(i%3==0){
			collection.collecttionContent = one.value;
		}
		if(i%3==1){
			collection.collecttionInfoId = one.value;
		}
		if(i%3==2){
			collection.collectType = one.value;
			collectionArray[number] = collection;

			number++;
		}
	}
	
	var  queryParamReg = {
			activityId: activityId,
			activityPhaseId: activityPhaseId,
			fdetailsId: fdetailsId
	};
	var params={
		coll:collectionArray,
		reg :queryParamReg,
		tmpMobile : $("#model1").val(),
		tmpName : $("#model2").val()
	};
	if(isCheck){
		$.ajax({  
			type: "post", // 请求方式  
			url: config.webCompletInfo, //url地址  
			data:JSON.stringify(params), //数据  
			contentType: "application/json",  
			dataType: "json",  
			success: function (result) {  
				joinFlag = true;//是否可以报名 false:未报名，true已报名	
				mui('.act-popover').popover('hide');
				
				mui.alert("完善信息成功");
				
			}, error: function () {  
				mui.alert("error");  
			}  
		});
	}
}*/

/**
 * 超时处理
 * @returns
 */
function completeInfoTimeOut(){
	$.ajax({  
		url:config.webCompleteInfoTimeOut,
		data:{  
			activityId		:	activityId,
			feedDetailid	:	fdetailsId,
			phaseId			:	activityPhaseId
		},  
		type:'POST',
		cache:true,  
		dataType:'json',  
		success:function(result) { 
			mui("#bxModal").popover("hide");
			setTimeout(function(){
				mui.alert("在规定时间内没有完善信息，报名申请取消",function(){
					window.location.reload();
				});
			},100);  
		} 
	});
}

/**
 * 跳转到活动评论
 * @returns
 */
function goActivityReview(){
	var alertFlag = 0;
	
    //评论提示语句
    if(joinFlag == true){
    	reviews='您还没有报名该活动，不能参与点评哦~';
    	alertFlag = 1;
    }else{
    	if(reviewFlag=="true"){
    		reviews='您已经点评过该活动~';
    		alertFlag = 2;
    	}else{
    		reviews='您已参加该活动，来说几句吧~';
    		alertFlag = 3;
    	}	
    }

	location.href = config.goActivityReview+"?activityId="+activityId+"&alertFlag=" + alertFlag;
	
}
//验证手机
function validateMobile(phone){
	var myreg = /^1[3|4|5|7|8]\d{9}$/;
	if(!myreg.test(phone)) 
	{ 
	    return false; 
	} 
	return true; 
}
/**
 * 发送私信
 */
function sendLetter(){
	var userType=$("#userType").val();
	var userLoginName=$("#userMobile").val();
	var openid=$("#openid").val();
	var qqOpenid=$("#qqOpenid").val();
	var xinlang=$("#xinlang").val();
	var twUserId=$("#twUserId").val();
	if(userType==1 || userType=="1"){
		if((""==userLoginName || null==userLoginName || userLoginName==undefined)
				&& (""==openid || null==openid || openid==undefined)
				&& (""==qqOpenid || null==qqOpenid || qqOpenid==undefined)
				&& (""==xinlang || null==xinlang || xinlang==undefined)
				&& (undefined!=twUserId && null!=twUserId && ""!=twUserId)){
			window.location.href = config.server+ "cyl/toWechatBand";
			return;
		} 
	}
	if($("#userType").val().length == 0){
		//mui.alert("未登录,不能进行此操作!");
		sessionStorage.removeItem("logins");
		sessionStorage.removeItem("binds");
		$("#signModel").show();
  		$(".mui-popup-backdrop").show();
	}else{
		location.href = BASE_URL+"/webChat/chartMain/toMessageList?msgType=004&chartFromUserid="+$("#userId").val();
	}
}